package com.atguigu.lease.admin.controller.user;

import com.atguigu.lease.admin.service.UserInfoService;
import com.atguigu.lease.model.bean.UserInfo;
import com.atguigu.lease.model.dto.UserInfoQueryDto;
import com.atguigu.lease.model.result.Response;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name="平台用户管理模块")
@RestController
@RequestMapping("/admin/user")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;
    @Operation(summary = "1、带条件分页查询平台用户列表")
    @GetMapping("/page")
    public Response<Page<UserInfo>> page(UserInfoQueryDto userInfoQueryDto) {
        //分页条件
        Page<UserInfo> page = new Page<>(userInfoQueryDto.getCurrent()
                , userInfoQueryDto.getSize());
        //过滤数据的条件
        LambdaQueryWrapper<UserInfo> wrapper = Wrappers.lambdaQuery(UserInfo.class)
                .select(UserInfo::getId , UserInfo::getPhone , UserInfo::getNickname ,
                        UserInfo::getAvatarUrl , UserInfo::getStatus) //只查询前端需要的列
                .eq(StringUtils.hasText(userInfoQueryDto.getStatus()),
                        UserInfo::getStatus, userInfoQueryDto.getStatus())
                .like(StringUtils.hasText(userInfoQueryDto.getPhone()),
                        UserInfo::getPhone, userInfoQueryDto.getPhone());
        userInfoService.page(page, wrapper);
        //数据脱敏： 将敏感数据 处理 不给前端  也不打印到日志中！
        return Response.ok(page);
    }
}
